// pages/doctor-my-data-rz/doctor-my-data-rz.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    doctorId: '',
    imgUrl: app.globalData.imgUrl,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadings();
  },

  //获取医生个人信息
  loadings: function() {
    var doctorId = wx.getStorageSync('userid');
    var that = this;
    app.request({
      url: 'doctor/doctor/doctorDetail',
      data: {
        'doctorId': doctorId
      },
      success(res) {
        wx.hideLoading();
        that.setData({
          picture: res.data[0],
          seniority: res.data[0].seniority,
          profession: res.data[0].profession,
          beauty: res.data[0].beauty,          
        })
      }
    })
  },
  //编辑医生证书
  present: function () {
    var that = this;
    var seniority = that.data.seniority;
    var profession = that.data.profession;
    var beauty = that.data.beauty;    
    app.request({
      url: 'doctor/doctor/aptitude',
      data: {
        'seniority': seniority,
        'profession': profession,
        'beauty': beauty,        
      },
      success(res) {
        that.loadings();
      }
    })
  },
  /**
   * loading加载
   */
  showLoading: function() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
  },
  // 资格证上传图片
  updateone: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ["original"],
      sourceType: ["album", "camera"],
      success: function (e) {
        var a = e.tempFilePaths[0];
        app.uploadFile({
          url: 'doctor/doctor/uploadCertFile',
          filePath: a,
          success: function (res) {
            var path = JSON.parse(res.data).data[0].filePath;
            that.setData({
              seniority: path
            })
            that.present();
          },
          fail: function (e) {
            console.log(e)
          }
        })
      }
    })
  },
  // 职业证上传图片
  updatetwo: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ["original"],
      sourceType: ["album", "camera"],
      success: function (e) {
        var a = e.tempFilePaths[0];
        app.uploadFile({
          url: 'doctor/doctor/uploadCertFile',
          filePath: a,
          success: function (res) {
            var path = JSON.parse(res.data).data[0].filePath;
            that.setData({
              profession: path
            })
            that.present();
          },
          fail: function (e) {
            console.log(e)
          }
        })
      }
    })
  },
  // 医疗美容医生主诊医生资格证上传图片
  updatethree: function () {
    var that = this;
    wx.chooseImage({
      count: 1,
      sizeType: ["original"],
      sourceType: ["album", "camera"],
      success: function (e) {
        var a = e.tempFilePaths[0];
        app.uploadFile({
          url: 'doctor/doctor/uploadCertFile',
          filePath: a,
          success: function (res) {
            var path = JSON.parse(res.data).data[0].filePath;
            that.setData({
              beauty: path
            })
            that.present();
          },
          fail: function (e) {
            console.log(e)
          }
        })
      }
    })
  },
 
})